define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'goods.library/index',
        add_url: 'goods.library/add',
        edit_url: 'goods.library/edit',
        delete_url: 'goods.library/delete',
        export_url: 'goods.library/export',
        modify_url: 'goods.library/modify',
        see_goods_url: 'goods.LibraryGoodsRelation/index',
        see_shop_url: 'goods.LibraryShopRelation/index',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar:['refresh','add','delete'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID',width: 80},
                    {field: 'name', title: '名称'},
                    {field: 'status', title: '状态', templet: ea.table.switch,tips:'展示|不展示',selectList:{0:'不展示',1:'展示'}},
                    {field: 'create_time', title: '创建时间',search:false},
                    {width: 350, title: '操作', templet: function (k, v) {
                            v.operat[0][0].title = '查看《'+k.name+"》的店铺"
                           return ea.table.tool(k,v)
                        },
                        operat: [
                            [{
                                text: '查看店铺',
                                url: init.see_shop_url,
                                method: 'open',
                                auth: 'see_shop',
                                fieldExtra:{'library_id':'id'},
                                class: 'layui-btn layui-btn-xs',
                                extend: 'data-full="true"',
                            },{
                                text: '查看商品',
                                url: init.see_goods_url,
                                method: 'open',
                                auth: 'see_goods',
                                fieldExtra:{'library_id':'id'},
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            }],
                            'edit',
                            'delete'
                        ]
                     },

                ]],
				done: function (){
                    $(".layui-table-body>table>tbody>tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                    });
                },
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});